Add, use an abstraction for testing url and url_link_text in preparation
authorrobertlipe <robertlipe@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Mon, 11 Feb 2013 03:17:22 +0000 (03:17 +0000)
committerrobertlipe <robertlipe@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Mon, 11 Feb 2013 03:17:22 +0000 (03:17 +0000)
for the day when it's not a string pointer.

git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@4305 f51c46e8-681c-474f-0cfe-069cfd0219fb

14 files changed:
gpsbabel/an1.cc
gpsbabel/csv_util.cc
gpsbabel/defs.h
gpsbabel/easygps.cc
gpsbabel/garmin_txt.cc
gpsbabel/gdb.cc
gpsbabel/geo.cc
gpsbabel/html.cc
gpsbabel/kml.cc
gpsbabel/lmx.cc
gpsbabel/mmo.cc
gpsbabel/tmpro.cc
gpsbabel/unicsv.cc
gpsbabel/vcf.cc

index b80f66a53aa4569e0252259b1ea174aa10edc4b6..a2263bacb3d0c2894214f31b231034cc72707aa5 100644 (file)
@@ -778,7 +778,7 @@ Write_One_AN1_Waypoint(const waypoint* wpt)
     xfree(extra);
   }
 
-  if (!nourl && wpt->url) {
+  if (!nourl && wpt->hasLink()) {
     int len = 7+strlen(wpt->url);
     char* extra = (char*)xmalloc(len);
     sprintf(extra, "{URL=%s}", wpt->url);
index 9f856ebb9d4a32c7ab32d4f3da686dc40942d49b..3cefc34cb28c11c19f093b43076b9dd9bb10ad0f 100644 (file)
@@ -1711,7 +1711,7 @@ xcsv_waypt_pr(const waypoint* wpt)
         strcpy(buff, xcsv_urlbase);
         off = strlen(xcsv_urlbase);
       }
-      if (wpt->url) {
+      if (wpt->hasLink()) {
         snprintf(buff + off, sizeof(buff) - off, fmp->printfc, wpt->url);
       } else {
         strcpy(buff, (fmp->val && *fmp->val) ? fmp->val : "\"\"");
@@ -1720,7 +1720,7 @@ xcsv_waypt_pr(const waypoint* wpt)
     break;
     case XT_URL_LINK_TEXT:
       snprintf(buff, sizeof(buff), fmp->printfc,
-               (wpt->url_link_text && *wpt->url_link_text) ? wpt->url_link_text : fmp->val);
+               (wpt->hasLinkText()) ? wpt->url_link_text : fmp->val);
       break;
     case XT_ICON_DESCR:
       writebuff(buff, fmp->printfc,
index 5a1caf0990433560484e5080792562de9f022070..9447a56b2dac80ee1f7cae98f8f002c62dada6a2 100644 (file)
@@ -540,6 +540,8 @@ public:
    * members must match struct url_link...
    */
   url_link* url_next;
+  bool hasLink() const {return url && *url; }
+  bool hasLinkText() const {return url && *url; }
   char* url;
   char* url_link_text;
 
index 1cdc3820edccaa3370c7f344eaf52e97e272b718..11c771cd7bacbb4211af78e22fa25d974b7abf29 100644 (file)
@@ -168,11 +168,11 @@ ez_disp(const waypoint* wpt)
     gbfputc(5, file_out);
     gbfputpstr(wpt->notes, file_out);
   }
-  if (wpt->url_link_text) {
+  if (wpt->hasLinkText()) {
     gbfputc(6, file_out);
     gbfputpstr(wpt->url_link_text, file_out);
   }
-  if (1 && wpt->url) {
+  if (wpt->hasLink()) {
     gbfputc(9, file_out);
     gbfputcstr(wpt->url, file_out);
   }
index 22a66d3b2054816fcf93dea45f15548e0063948c..12bcd60cbf20f942f0e662118f18b33d1d535641 100644 (file)
@@ -619,7 +619,7 @@ write_waypt(const waypoint* wpt)
   country = gt_get_icao_country(GMSD_GET(cc, ""));
   print_string("%s\t", (country != NULL) ? country : "");
   print_date_and_time(wpt->creation_time, 0);
-  print_string("%s\t", wpt->url ? wpt->url : "");
+  print_string("%s\t", wpt->hasLink() ? wpt->url : "");
   print_categories(GMSD_GET(category, 0));
 
   gbfprintf(fout, "\r\n");
index 2227f17059e46bf78760a85f010e4e9303554aae..a6de7878ae6464a2d6c0fc469b58f0d6e5f6f842 100644 (file)
@@ -457,7 +457,7 @@ read_file_header(void)
   reclen = FREAD_i32;
   i = FREAD(buf, reclen + 1);
   if (global_opts.verbose_status > 0) {
-    char* name = buf+2;
+    const char* name = buf+2;
     if (strstr(name, "SQA") == 0) {
       name = "MapSource";
     } else if (strstr(name, "neaderhi") == 0) {
@@ -1375,7 +1375,7 @@ write_waypoint(
     FWRITE_CSTR(str);                          /* instruction */
 
     cnt = 0;
-    if (wpt->url) {
+    if (wpt->hasLink()) {
       cnt++;
     }
     for (url_next = wpt->url_next; (url_next); url_next = url_next->url_next)
@@ -1383,7 +1383,7 @@ write_waypoint(
         cnt++;
       }
     FWRITE_i32(cnt);
-    if (wpt->url) {
+    if (wpt->hasLink()) {
       FWRITE_CSTR(wpt->url);
     }
     for (url_next = wpt->url_next; (url_next); url_next = url_next->url_next)
index c30109f7065285b06c0af9abd43081581a5ecb49..0d21ea059ec41800b3e611f2e014f8f7c261f1e1 100644 (file)
@@ -270,7 +270,7 @@ geo_waypt_pr(const waypoint* waypointp)
 
   writer.writeTextElement("type", deficon ? deficon : waypointp->icon_descr);
 
-  if (waypointp->url) {
+  if (waypointp->hasLink()) {
     writer.writeStartElement("link");
     writer.writeAttribute("text ", "Cache Details");
     writer.writeCharacters(waypointp->url);
index 9e21da9aaaa450c1abaf4627ad01cfac75a75a3d..27c192e0c14c15fdd38575f5d16429f7c190d641 100644 (file)
@@ -108,7 +108,7 @@ html_disp(const waypoint* wpt)
   }
   gbfprintf(file_out, "<br>\n");
   if (strcmp(wpt->description, wpt->shortname)) {
-    if (wpt->url) {
+    if (wpt->hasLink()) {
       char* d = html_entitize(wpt->description);
       gbfprintf(file_out, "<a href=\"%s\">%s</a>", wpt->url, d);
       xfree(d);
index 4e403e614a4a4918b42d3254c6a05c5570f6001a..fb797453e3df705075636e0a513e972b867f43b4 100644 (file)
@@ -1448,7 +1448,7 @@ static void kml_geocache_pr(const waypoint* waypointp)
     xfree(p);
   }
 
-  if (waypointp->url_link_text) {
+  if (waypointp->hasLinkText()) {
     p = xml_entitize(waypointp->url_link_text);
     kml_write_xml(0, "<Data name=\"gc_name\"><value>%s</value></Data>\n", p);
     xfree(p);
@@ -1528,11 +1528,11 @@ static void kml_waypt_pr(const waypoint* waypointp)
   kml_write_xmle("name", waypointp->shortname);
 
   // Description
-  if (waypointp->url && waypointp->url[0]) {
+  if (waypointp->hasLink()) {
     char* odesc = xml_entitize(waypointp->url);
     kml_write_xml(0, "<snippet/>\n");
     kml_write_xml(0, "<description>\n");
-    if (waypointp->url_link_text && waypointp->url_link_text[0])  {
+    if (waypointp->hasLinkText()) {
       char* olink = xml_entitize(waypointp->url_link_text);
       kml_write_xml(0, "<![CDATA[<a href=\"%s\">%s</a>]]>", odesc, olink);
       xfree(olink);
index 66c71deb0f87c5f13e289168347ae948fe4eb953..09573ab940c8dec9e5fc6e598603ec47bfe3f55f 100644 (file)
@@ -237,12 +237,12 @@ lmx_print(const waypoint* wpt)
   }
   lmx_end_tag(0x4A, 3); // coordinates
 
-  if (wpt->url && wpt->url[0]) {
+  if (wpt->hasLink()) {
     lmx_start_tag(0x65, 3); // mediaLink
     if (!binary) {
       gbfputc('\n', ofd);
     }
-    if (wpt->url_link_text) {
+    if (wpt->hasLinkText()) {
       lmx_write_xml(0x48, wpt->url_link_text, 4);  // name
     }
     lmx_write_xml(0x67, wpt->url, 4); // url
index bbe234944cf962ffd54fd7d378bec91edb73f07d..b86e5c6400c7bc10e42b4d2884d4a1e0b0da5419 100644 (file)
@@ -547,7 +547,7 @@ mmo_read_CObjWaypoint(mmo_data_t* data)
       wpt->notes = xstrdup(cend);
     }
 
-    if (wpt->url) {
+    if (wpt->hasLink()) {
       DBG((sobj, "url = \"%s\"\n", wpt->url));
     }
   } else if (*str) {
@@ -1013,7 +1013,7 @@ mmo_finalize_rtept_cb(const waypoint* wptref)
     if (wpt2->notes) {
       wpt->notes = xstrdup(wpt2->notes);
     }
-    if (wpt2->url) {
+    if (wpt2->hasLink()) {
       wpt->notes = xstrdup(wpt2->url);
     }
 
@@ -1310,7 +1310,7 @@ mmo_write_wpt_cb(const waypoint* wpt)
     gbfputuint16(0, fout);  /* extra bytes */
   }
 
-  if (wpt->url && *wpt->url) {
+  if (wpt->hasLink()) {
     str = xstrdup("_FILE_ ");
     str = xstrappend(str, wpt->url);
     str = xstrappend(str, "\n");
index 94cb02ff1dce9d94a84c9abbca65019eb5eba9f4..58911d0ffdf3a1258f0dc41d536b4b89c832c06f 100644 (file)
@@ -220,7 +220,7 @@ tmpro_waypt_pr(const waypoint * wpt)
             wpt->altitude,
             colour,
             icon,
-            wpt->url ? wpt->url : ""
+            wpt->hasLink() ? wpt->url : ""
            );
 
 
index 42d8d831fd6cdb97c0d778ad2317bdf8cd3f7b9f..3d5dc16b49fee40853f973bcf112c077bc8b0465 100644 (file)
@@ -1356,7 +1356,7 @@ unicsv_waypt_enum_cb(const waypoint *wpt)
       gb_setbit(&unicsv_outp_flags, fld_notes);
     }
   }
-  if (wpt->url && *wpt->url) {
+  if (wpt->hasLink()) {
     gb_setbit(&unicsv_outp_flags, fld_url);
   }
   if (wpt->creation_time != 0) {
index 9fee87eaa836090bf3b3539f7d988cb62c60edb3..b0e5866849ae59045be00579aafeaef47dce8541 100644 (file)
@@ -104,7 +104,7 @@ vcf_disp(const waypoint *wpt)
   gbfprintf(file_out, "N:%s;%s;;;\n", wpt->description,wpt->shortname);
   gbfprintf(file_out, "ADR:%c%d %06.3f %c%d %06.3f\n", wpt->latitude < 0 ? 'S' : 'N',  abs(latint), 60.0 * (fabs(wpt->latitude) - latint), wpt->longitude < 0 ? 'W' : 'E', abs(lonint), 60.0 * (fabs(wpt->longitude) - lonint));
 
-  if (wpt->url) {
+  if (wpt->hasLink()) {
     gbfprintf(file_out, "URL:%s\n", wpt->url);
   }